home *** CD-ROM | disk | FTP | other *** search
/ Shareware Super Platinum 8 / Shareware Super Platinum 8.iso / mac / WIN_PRO / DS-1.ZIP;1 / PREPROC.ZIP / PREPROC.H < prev    next >
Encoding:
C/C++ Source or Header  |  1992-02-10  |  7.1 KB  |  225 lines

  1. #include "../h/gsupport.h"
  2.  
  3. /*
  4.  * The include file for #defines for tokens can be overridden
  5.  *  by a -DTokDotH=... compiler option. This is useful for
  6.  *  creating an embedded preprocessor where token definitions are
  7.  *  generated by yacc from a grammar.
  8.  */
  9. #ifndef TokDotH
  10. #define TokDotH "../preproc/ptoken.h"
  11. #endif                    /* TokDotH */
  12. #include TokDotH
  13.  
  14. /*
  15.  * If Bell is not defined, determine the default value for the "bell"
  16.  *   character.
  17.  */
  18. #ifndef Bell
  19. #ifdef StandardC
  20. #define Bell '\a'
  21. #else                    /* StandardC */
  22. #if EBCDIC
  23. #define Bell '\x2F'
  24. #else                    /* EBCDIC */
  25. #define Bell '\007'
  26. #endif                    /* EBCDIC */
  27. #endif                    /* StandardC */
  28. #endif                    /* Bell */
  29.  
  30. #define CBufSize 256  /* size of buffer for file input */
  31.  
  32. /*
  33.  * Identification numbers for tokens for which there are no definitions
  34.  *   generated from a C grammar by yacc.
  35.  */
  36. #define WhiteSpace 1001   /* white space */
  37. #define PpNumber   1002   /* number (integer or real) */
  38. #define PpIf       1003   /* #if */
  39. #define PpElse     1004   /* #else */
  40. #define PpIfdef    1005   /* #ifdef */
  41. #define PpIfndef   1006   /* #ifndef */
  42. #define PpElif     1007   /* #elif */
  43. #define PpEndif    1008   /* #endif */
  44. #define PpInclude  1009   /* #include */
  45. #define PpDefine   1010   /* #define */
  46. #define PpUndef    1011   /* #undef */
  47. #define PpLine     1012   /* #line */
  48. #define PpError    1013   /* #error */
  49. #define PpPragma   1014   /* #pragma */
  50. #define PpPaste    1015   /* ## */
  51. #define PpDirEnd   1016   /* new-line terminating a directive */
  52. #define PpHeader   1017   /* <...> from #include */
  53. #define PpBegdef   1018   /* #begdef */
  54. #define PpEnddef   1019   /* #enddef */
  55. #define PpNull     1020   /* # */
  56. #define PpKeep     1021   /* directive specific to an application, pass along */
  57. #define PpSkip     1022   /* directive specific to an application discard */
  58. #define Invalid    9999   /* marker */
  59.  
  60. extern char *progname; /* name of this program: for error messages */
  61. extern line_cntrl;     /* flag: are line directives needed in the output */
  62.  
  63. /*
  64.  * whsp_image determines whether the spelling of white space is not retained,
  65.  *   is retained with each comment replaced by a space, or the full spellling
  66.  *   of white space and comments is retained.
  67.  */
  68. #define NoSpelling 0
  69. #define NoComment  1
  70. #define FullImage  2
  71.  
  72. extern int whsp_image;
  73.  
  74. extern int max_recurse;        /* how much recursion is allows in macros */
  75. extern struct token *zero_tok; /* token "0" */
  76. extern struct token *one_tok;  /* token "1" */
  77.  
  78. extern int *first_char;        /* first character in tokenizing buffer */
  79. extern int *next_char;         /* next character in tokenizing buffer */
  80. extern int *last_char;         /* last character in tokenizing buffer */
  81.  
  82. /*
  83.  * Entry in array of preprocessor directive names.
  84.  */
  85. struct rsrvd_wrd {
  86.    char *s;         /* name (without the #) */
  87.    int tok_id;      /* token id of directive */
  88.    };
  89.  
  90. /*
  91.  * token flags:
  92.  */
  93. #define LineChk  0x1   /* A line directive may be needed in the output */
  94. #define NoExpand 0x2   /* Don't macro expand this identifier */
  95.  
  96. /*
  97.  * Token.
  98.  */
  99. struct token {
  100.    int tok_id;        /* token identifier */
  101.    char *image;        /* string image of token */
  102.    char *fname;         /* file name of origin */
  103.    int line;            /* line number of origin */
  104.    int flag;            /* token flag, see above */
  105.    struct token *next;
  106.    };
  107.  
  108. /*
  109.  * Token list.
  110.  */
  111. struct tok_lst {
  112.    struct token *t;      /* token */
  113.    struct tok_lst *next; /* next entry in list */
  114.    };
  115.  
  116. /*
  117.  * Identifier list.
  118.  */
  119. struct id_lst {
  120.    char *id;            /* identifier */
  121.    struct id_lst *next; /* next entry in list */
  122.    };
  123.  
  124. /*
  125.  * a macro, m, falls into one of several categores:
  126.  *   those with arguments                - m.category = # args >= 0
  127.  *   those with no arguments             - m.category = NoArgs
  128.  *   those that may not be chaged        - m.category = FixedMac
  129.  *   those that require special handling - m.category = SpecMac
  130.  */
  131. #define NoArgs   -1
  132. #define FixedMac -2
  133. #define SpecMac  -3
  134.  
  135. struct macro {
  136.    char *mname;
  137.    int category;
  138.    int multi_line;
  139.    struct id_lst *prmlst;
  140.    struct tok_lst *body;
  141.    int ref_cnt;
  142.    int recurse;
  143.    struct macro *next;
  144.    };
  145.  
  146. /*
  147.  * states for recongizing preprocessor directives
  148.  */
  149. #define Reset    1
  150. #define CanStart 2   /* Just saw a new-line, look for a directive */
  151. #define Within   3   /* Next new-line ends directive */
  152.  
  153. /*
  154.  * Information for a source of tokens created from a character stream.
  155.  *  The characters may come from a file, or they be in a prefilled buffer.
  156.  */
  157. struct char_src {
  158.    FILE *f;               /* file, if the chars come directly from a file */
  159.    char *fname;          /* name of file */
  160.    int bufsize;          /* size of character buffer */  
  161.    int *char_buf;         /* pointer to character buffer */
  162.    int *line_buf;      /* buffer of lines characters come from */
  163.    int *next_char;      /* next unprocessed character in buffer */
  164.    int *last_char;      /* last character in buffer */
  165.    int line_adj;      /* line adjustment caused by #line directive */
  166.    int dir_state;      /* state w.r.t. recognizing directives */
  167.    struct token *tok_sav; /* used to save token after look ahead */
  168.    struct char_src *next;
  169.    };
  170.  
  171. /*
  172.  * Information for a source of tokens dirived from expanding a macro.
  173.  */
  174. struct mac_expand {
  175.    struct macro *m;          /* the macro being expanded */
  176.    struct tok_lst **args;     /* list of arguments for macro call */
  177.    struct tok_lst **exp_args; /* list of expanded arguments for macro call */
  178.    struct tok_lst *rest_bdy;  /* position within the body of the macro */
  179.    struct mac_expand *next;
  180.    };
  181.  
  182. /*
  183.  * Elements in a list of token lists used for token pasting.
  184.  */
  185. struct paste_lsts {
  186.    struct token *trigger;   /* the token pasting operator */
  187.    struct tok_lst *tlst;    /* the token list */
  188.    struct paste_lsts *next; /* the next element in the list of lists */
  189. };
  190.  
  191. /*
  192.  * Pointers to various token sources.
  193.  */
  194. union src_ref {
  195.    struct char_src *cs;      /* source is tokenized characters */
  196.    struct mac_expand *me;    /* source is macro expansion */
  197.    struct tok_lst *tlst;     /* source is token list (a macro argument) */
  198.    struct paste_lsts *plsts; /* source is token lists for token pasting */
  199.    };
  200.    
  201. /*
  202.  * Types of token sources:
  203.  */
  204. #define CharSrc   0     /* tokenized characters */
  205. #define MacExpand 1     /* macro expansion */
  206. #define TokLst    2     /* token list */
  207. #define PasteLsts 4    /* paste last token of 1st list to fisrt of 2nd */
  208. #define DummySrc  5     /* base of stack */
  209.  
  210. #define NTokSav  2      /* maximum number of tokens that can be pushed back */
  211.  
  212. struct src {
  213.    int flag;            /* indicate what kind of source it is */
  214.    struct tok_lst *cond;    /* list of nested conditionals in effect */
  215.    struct token *toks[NTokSav];    /* token push-back stack for preproc() */
  216.    int ntoks;            /* number of tokens on stack */
  217.    struct src *next;        /* link for creating stack */
  218.    union src_ref u;             /* pointer to specific kind of source */
  219.    };
  220.  
  221. extern struct src dummy;       /* base of stack */
  222.  
  223. extern struct src *src_stack;  /* source stack */
  224.  
  225.